﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OneMile.Common;
using System.Configuration;
using System.Data.SqlClient;

namespace OneMile.DAL
{
    public abstract class BaseDAL
    {
        protected static string conStr = ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString;

        private SqlConnection _connection;
        protected SqlConnection Con
        {  get
            {
               _connection=new SqlConnection(conStr);
               return _connection;
            }
        }

        /// <summary>
        /// 打开连接
        /// </summary>
        /// <returns></returns>
        protected bool DbOpen()
        {
            try
            {
                _connection.Open();
                return true;
            }
            catch (Exception ex)
            {
                //("打开数据库出错:" + e.Message);
                return false;
            }
        }

        /// <summary>
        /// 关闭连接
        /// </summary>
        /// <returns></returns>
        protected bool DbClose()
        {
            try
            {
                _connection.Close();
                return true;
            }
            catch (Exception ex)
            {
                //("关闭数据库出错:" + e.Message);
                return false;
            }
        }

       protected void WriteLog(string log)
       {
           ErrorLogWriter.Write(log); 
       }
    }
}
